package com.moshme.web.controller.project;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.moshme.common.annotation.Log;
import com.moshme.common.core.controller.BaseController;
import com.moshme.common.core.domain.AjaxResult;
import com.moshme.common.enums.BusinessType;
import com.moshme.project.domain.StageSurveyGasMcv;
import com.moshme.project.service.StageSurveyGasMcvService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author Kieyfr
 * @version 1.0
 * @description 燃气主控阀控制器
 * @date 2023/9/7 19:03
 */
@RestController
@RequestMapping("stageSurveyGasMcv")
public class StageSurveyGasMcvController extends BaseController {

    @Autowired
    private StageSurveyGasMcvService stageSurveyGasMcvService;

    /**
     * 查询某个燃气主控阀
     * @param id
     * @return
     */
    @Log(title = "查询某个燃气主控阀")
    @GetMapping
    @ApiOperation(value = "查询某个燃气主控阀")
    @ApiImplicitParam(name="id",value="燃气主控阀id")
    public AjaxResult get(Long id) {
        return success(stageSurveyGasMcvService.getById(id));
    }

    /**
     * 查询项目的全部燃气主控阀
     * @param projectId
     * @return
     */
    @Log(title = "查询项目的全部燃气主控阀")
    @GetMapping("project")
    @ApiOperation(value = "查询项目的全部燃气主控阀")
    public AjaxResult getProjectList(Long projectId) {
        return success(stageSurveyGasMcvService.getListByProject(projectId));
    }

    /**
     * 新增燃气主控阀
     * @param stageSurveyGasMcv
     * @return
     */
    @Log(title = "新增燃气主控阀", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增燃气主控阀")
    public AjaxResult add(@RequestBody StageSurveyGasMcv stageSurveyGasMcv) {
        if (!stageSurveyGasMcvService.save(stageSurveyGasMcv)){
            return error("添加失败");
        }
        return success("添加成功");
    }

    /**
     * 修改燃气主控阀
     * @param stageSurveyGasMcv
     * @return
     */
    @Log(title = "修改燃气主控阀", businessType = BusinessType.INSERT)
    @PutMapping
    @ApiOperation(value = "修改燃气主控阀")
    public AjaxResult update(@RequestBody StageSurveyGasMcv stageSurveyGasMcv) {
        if (!stageSurveyGasMcvService.updateById(stageSurveyGasMcv)){
            return error("修改失败");
        }
        return success("修改成功");
    }

    /**
     * 删除燃气主控阀
     * @param id
     * @return
     */
    @Log(title = "删除燃气主控阀", businessType = BusinessType.DELETE)
    @DeleteMapping
    @ApiOperation(value = "删除燃气主控阀")
    @ApiImplicitParam(name="id",value="燃气主控阀id")
    public AjaxResult del(Long id) {
        if (!stageSurveyGasMcvService.removeById(id)){
            return error("删除失败");
        }
        return success("删除成功");
    }

}
